home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000281 / patchSG0000281.idb / usr / include / sys / grio.h.z / grio.h
Encoding:
C/C++ Source or Header  |  1995-06-12  |  9.9 KB  |  321 lines

  1. /*                                                                        *
  2.  *               Copyright (C) 1989, Silicon Graphics, Inc.               *
  3.  *                                                                        *
  4.  *  These coded instructions, statements, and computer programs  contain  *
  5.  *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
  6.  *  are protected by Federal copyright law.  They  may  not be disclosed  *
  7.  *  to  third  parties  or copied or duplicated in any form, in whole or  *
  8.  *  in part, without the prior written consent of Silicon Graphics, Inc.  *
  9.  *                                                                        *
  10.  **************************************************************************/
  11.  
  12. #ident "$Revision: 1.2 $"
  13. #ifndef _GRIO_H_
  14. #define _GRIO_H_
  15.  
  16. /*
  17.  * This include file contains the definitions and structures necessary
  18.  * for a user process to make guaranteed rate i/o requests.
  19.  */
  20.  
  21. /* 
  22.  * grio_resv structure is filled in by the user process and is sent to the
  23.  * library routine grio_request() along with the file descriptor of the 
  24.  * resouce for which the I/O rate guarantee is being requested.
  25.  * 
  26.  * The grio_request() call will return 0 if there are no errors. If there
  27.  * is an error the routine will return -1 and the gr_error field will 
  28.  * contain the error number. In addition, if the guarantee request is
  29.  * denied due to lack of device bandwidth, then gr_optime, and gr_opsize
  30.  * will contain values describing the maximum remaining bandwidth.
  31.  *
  32.  *
  33.  * Return errors are:
  34.  *     The first two errors indicate an error in the library.
  35.  *        EINVAL        - could not communicate to daemon
  36.  *        ESRCH        - invalid procid 
  37.  *
  38.  *    These errors indicate an error in the calling process.
  39.  *        EBADF        - could not stat file or file already
  40.  *                  has a guarantee
  41.  *        EIO        - start time is incorrect
  42.  *        ENOSPC        - bandwidth could not be allocated
  43.  *        ENOENT        - file does not contain any extents.
  44.  *        EACCES        - cannot provide desired level of 
  45.  *                  guarantee (i.e HARD vs SOFT)
  46.  */
  47.  
  48. #define MAX_ERRORDEV_NAME    32
  49.  
  50. typedef struct grio_resv {
  51.     time_t    gr_start;    /* when to start in seconds                */
  52.     u_long    gr_duration;    /* how long the guarntee will last, in secs */
  53.     u_long    gr_optime;    /* time to complete the op in secs         */
  54.     u_long    gr_opsize;    /* size of each op in bytes            */
  55.     u_long    gr_flags;    /* flags field                     */
  56.     u_long    gr_error;    /* returned: error code                  */
  57.     char    gr_errordev[MAX_ERRORDEV_NAME];/* device that caused error  */
  58. } grio_resv_t;
  59.  
  60.  
  61. /* 
  62.  * This structure is used to return statistics info to the caller.
  63.  * It is used with GRIO_GET_INFO resv_type.
  64.  *    subcommands are:
  65.  *        GRIO_DEV_RESVS:
  66.  *            return number of reservations on the device 
  67.  *            identified by ( device_name) in grio_blk_t
  68.  *            structure.
  69.  *        GRIO_FILE_RESVS:    
  70.  *            return number of reservations on the file 
  71.  *            identified by ( fs_dev, ino) pair in grio_blk_t
  72.  *            structure.
  73.  *        GRIO_PROC_RESVS:
  74.  *            return number of reservations for the process 
  75.  *            identified by ( procid ) in grio_blk_t structure.
  76.  */
  77. typedef struct grio_stats {
  78.     /*
  79.      * value dependent on the subcommand and grio_blk_t parameters.
  80.      */
  81.     u_long    gs_count;        /* current number of reservations
  82.                      * active on the device/file/proc
  83.                      */
  84.     u_long    gs_maxresv;        /* maximum number of reservations
  85.                      * allowed on the device.
  86.                      * for file/proc this is the number
  87.                      * of licensed streams.
  88.                      */
  89.     u_long    gs_optiosize;        /* size of the optimal i/o size
  90.                      * in bytes for this device.
  91.                      * not defined for file/proc.
  92.                      */
  93.  
  94.     /*
  95.      * independent of subcommand - always returned to caller.
  96.      * these are system wide totals.
  97.      */
  98.     u_long    gs_resvcount;        /* number of reservation requests 
  99.                      * that were granted.
  100.                      */
  101.     u_long    gs_unresvcount;        /* number of unreserve requests
  102.                      * that were performed.
  103.                      */
  104.     u_long  gs_resvdeniedcount;    /* number of reservation requests
  105.                      * that were denied
  106.                       */
  107. } grio_stats_t;
  108.  
  109. /* 
  110.  * Defines for the gr_flags field.
  111.  */
  112. #define EXTENT_ALIGNED    0x00000001
  113. #define HARD_GUARANTEE    0x00000002
  114. #define SOFT_GUARANTEE    0x00000004
  115. #define TIME_GUARANTEE    0x00000008
  116. #define GUARANTEE_MASK    0x000000FF
  117.  
  118. #define VOD_LAYOUT    0x00000100
  119.  
  120. #define DEVICE_NAME_SIZE    15
  121.  
  122. extern int grio_request( int,  grio_resv_t *);
  123. extern int grio_info_request( int, int, pid_t, char *, grio_stats_t *);
  124. extern int grio_remove_request( int,  grio_resv_t *);
  125. extern int grio_get_rtgkey(int, uuid_t *);
  126. extern int grio_use_rtgkey(int, uuid_t *);
  127.  
  128. /*
  129.  * The grio_request() library routine fills in this structure and writes
  130.  * it to the ggd deamon.
  131.  */
  132. typedef struct grio_block {
  133.         int             resv_type;              /* type of reservation req */
  134.     int        sub_cmd;        /* subcommand - only used for
  135.                          * GET_INFO commands
  136.                          */
  137.         int             fd;                     /* file descriptor         */
  138.         dev_t           fs_dev;                 /* file system dev_t       */
  139.         pid_t           procid;                 /* process id of requestor */
  140.         __uint64_t      ino;                    /* inode number            */
  141.     char        device_name[DEVICE_NAME_SIZE];
  142.     union {
  143.             grio_resv_t     grio_resv;      /* grio request info       */
  144.         uuid_t        uuid;        /* rate transfer ticket    */
  145.                         /* NOTE: when this union 
  146.                          * contains a valid uuid
  147.                          * the grio_resv.gr_error
  148.                          * field can still safely 
  149.                          * return an error code.
  150.                          * The uuid_t struct is
  151.                          * only 16 bytes long.
  152.                          */
  153.         grio_stats_t    grio_stats;
  154.     } data;
  155. } grio_blk_t;
  156.  
  157. /*
  158.  * This structure is passed from the ggd to the kernel to 
  159.  * create a rate guaranteed ticket for an inode.
  160.  */
  161. typedef struct reservation_id {
  162.     __uint64_t    ino;
  163.     dev_t        fs_dev;
  164.     pid_t        pid;
  165.     int        vod_rotate_slot;
  166.     int        vod_group_size;
  167. } reservation_id_t;
  168.  
  169. #define        NULL_VOD_SLOT        -1
  170. #define        IS_VALID_VOD(slot)    (slot != NULL_VOD_SLOT)
  171.  
  172.  
  173. /*
  174.  * Structure definitions with fields defined as known sizes.
  175.  * This is done to have a layer of abstraction between the kernel and the
  176.  * ggd daemon. The kernel can have 32 bit inumber, file sizes, and file
  177.  * system sizes, but the ggd will always view them as 64 bit quantities.
  178.  */
  179. typedef struct grio_file_id {
  180.     __uint64_t    ino;
  181.     dev_t        fs_dev;
  182. } file_id_t;
  183.  
  184. typedef struct grio_bmbt_irec {
  185.     __uint64_t    br_startoff;
  186.     __uint64_t    br_startblock;
  187.     __uint64_t    br_blockcount;
  188. } grio_bmbt_irec_t;
  189.  
  190.  
  191. #define REQ_ID_PID_OFFSET       7
  192. #define REQ_ID_VCOUNT_OFFSET    0
  193. #define REQ_ID_VCOUNT_MASK      0xffffff80
  194.  
  195. #define MAKE_REQ_PID( pid, vcount)    \
  196.         ((pid << REQ_ID_PID_OFFSET) | (vcount))
  197.  
  198. #define MATCH_PID( pid1, pid2)  \
  199.         (((pid1) & (REQ_ID_VCOUNT_MASK)) == ((pid2) & (REQ_ID_VCOUNT_MASK)))
  200.  
  201. #define MATCH_ID(id1, id2) \
  202.         ((id1->ino == id2->ino) && MATCH_PID(id1->pid,id2->pid))
  203.  
  204. #define MATCH_FULL_ID(id1, id2) \
  205.         ((id1->ino == id2->ino) && (id1->pid == id2->pid))
  206.  
  207. #define MATCH_DEV_ID(id1,id2)                \
  208.         ((id1->ino == id2->ino)       &&    \
  209.          (id1->fs_dev == id2->fs_dev) &&      \
  210.           MATCH_PID((ulong_t)(id1->pid),(ulong_t)(id2->pid)) )
  211.  
  212. #define MATCH_DEV_FULL_ID(id1, id2)             \
  213.             ((id1->ino == id2->ino)       &&    \
  214.          (id1->fs_dev == id2->fs_dev) &&      \
  215.              (id1->pid == id2->pid))
  216.  
  217. #define GRIO_PIPE               "/tmp/grio.pipe"
  218. #define GRIO_PIPE_STRLEN        14
  219. #define GRIO_PID_LEN            10
  220. #define GRIO_PIPE_NAMLEN        GRIO_PIPE_STRLEN + GRIO_PID_LEN
  221. #define GRIO_LOCK_FILE        "/tmp/grio.lock"
  222.  
  223. /*
  224.  * Commands for the resv_type field.
  225.  */
  226. #define GRIO_RESV_FILE          1    /* request rate guarantee on a file   */
  227. #define GRIO_RESV_OTHER         2    /* request rate guarantee on a device */
  228. #define GRIO_GET_INFO         3    /* request rate info on node          */
  229. #define GRIO_GET_TREE_INFO      4    /* request rate tree info             */
  230. #define GRIO_UNRESV_FILE    5    /* remove rate guarantee on a file    */
  231. #define GRIO_UNRESV_FILE_ASYNC    6    /* kernel - remove rate guarantee     */
  232. #define GRIO_PURGE_VDEV_ASYNC    7    /* kernel - purge vdisk info cache    */
  233. #define GRIO_GET_RGT_KEY    8
  234. #define GRIO_USE_RGT_KEY    9
  235.  
  236. /*
  237.  * Subcommands for the GRIO_GET_INFO command.
  238.  */
  239. #define GRIO_FILE_RESVS        0
  240. #define GRIO_DEV_RESVS        1
  241. #define GRIO_PROC_RESVS        2
  242.  
  243. #define GRIO_ASYNC_REQ(cmd)    \
  244.     ((cmd == GRIO_UNRESV_FILE_ASYNC) || (cmd == GRIO_PURGE_VDEV_ASYNC))
  245.  
  246. /*
  247.  * syssgi SGI_GRIO commands
  248.  */
  249. #define GRIO_ADD_DISK_INFO       1
  250. #define GRIO_UPDATE_DISK_INFO   2
  251. #define GRIO_ADD_FILE_TICKET    3
  252. #define GRIO_REMOVE_FILE_TICKET 4
  253. #define GRIO_GET_DISK_INFO      5
  254. #define GRIO_GET_FILE_EXTENTS   6
  255. #define GRIO_GET_FS_BLOCK_SIZE  7
  256. #define GRIO_GET_INVENT      8
  257. #define GRIO_GET_INVENT_START      9
  258. #define GRIO_GET_FILE_RT    10
  259. #define GRIO_REMOVE_ALL_TICKETS    11
  260. #define GRIO_WRITE_GRIO_REQ     12
  261. #define GRIO_READ_GRIO_REQ     13
  262. #define GRIO_WRITE_GRIO_RESP    14
  263. #define GRIO_MARK_INODE_GRIO    15
  264. #define GRIO_CLEAR_INODE_GRIO    16
  265. #define GRIO_CREATE_RGT_KEY    17
  266.  
  267.  
  268.  
  269. #ifdef _KERNEL
  270. /*
  271.  * Kernel buffer scheduling structure.
  272.  */
  273. typedef struct grio_disk_info {
  274.         int             num_ios_max;
  275.         int             num_ios_rsv;
  276.         int             num_ios_pnd;
  277.         int             opt_blk_sz;
  278.         lock_t          lock;
  279.     buf_t        bp;
  280.         buf_t           *firstbp;               /* use av_forw field in bp */
  281.         buf_t           *lastbp;                /* use av_back field in bp */
  282. } grio_disk_info_t;
  283.  
  284. /*
  285.  * Types of tickets.
  286.  *
  287.  */
  288. #define        ROTATE_TYPE    1
  289. #define        NON_ROTATE_TYPE    2
  290.  
  291. #define ROTATE_TICKET(ticket)        (ticket->type == ROTATE_TYPE)
  292. #define NON_ROTATE_TICKET(ticket)    (ticket->type == NON_ROTATE_TYPE)
  293.  
  294. /*
  295.  * Kernel rate guarantee ticket. This is attached to the inode
  296.  * of the file used for grio.
  297.  */
  298. typedef struct grio_ticket {
  299.     int            type;
  300.     int            rotator_slot;
  301.     int            rotator_group_size;
  302.     int            sz;
  303.     struct reservation_id    id;
  304.     timestruc_t        lastreq;
  305.     int            iothissecond;
  306.     struct grio_ticket    *nextticket;
  307. } grio_ticket_t;
  308.  
  309. extern int grio_strat( buf_t *);
  310. extern void grio_iodone( buf_t *);
  311. extern int grio_config( int, int, int, int, int );
  312. #endif
  313.  
  314. /*
  315.  *  defines for grio stream count
  316.  */
  317. #define DEFAULT_GRIO_STREAMS    4
  318. #define UNLIMITED_GRIO_STREAMS  0x100000
  319.  
  320. #endif /* _GRIO_H_ */
  321.